package de.clapp.client.musicbox;

import java.awt.EventQueue;

import javax.swing.JSlider;

import uk.co.caprica.vlcj.player.MediaPlayer;

public class TimerThread extends Thread
{
    private final JSlider slider;
    
    private final MediaPlayer player;

    private boolean cancel = false;

    public TimerThread(final JSlider slider, final MediaPlayer player)
    {
        this.slider = slider;
        this.player = player;
    }

    public void cancel()
    {
        this.cancel = true;
    }

    @Override
    public void run()
    {
        while (!this.cancel)
        {
            try
            {
                EventQueue.invokeLater(new Runnable()
                {

                    @Override
                    public void run()
                    {
//                        int value = TimerThread.this.slider.getValue();
//                        TimerThread.this.slider.setValue(value + 1);
                        TimerThread.this.slider.setValue((int)(player.getTime() / 1000));
                    }
                    
                });
                Thread.sleep(1000);
            }
            catch (InterruptedException e)
            {
                e.printStackTrace();
            }
        }
    }
}
